﻿@{
    List<SmallJob.Model.Category> catgories = null;
    if(ViewData["categories"]!=null){
        catgories =  ViewData["categories"]  as List<SmallJob.Model.Category>;
    } else {
        catgories = new SmallJob.Services.Implements.CategoryService(new SmallJob.Data.DatabaseFactory()).All().ToList();
    }
    var user =  Session["user"] as SmallJob.Model.User;
}
<!DOCTYPE html>
<html>
<head>
    <meta  content="text/html;charset=UTF-8" />
    <title>@ViewBag.Title</title>
    <link rel="stylesheet" media="screen" type="text/css" href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")"/>
    <link rel="stylesheet" media="screen" type="text/css" href="@Url.Content("~/Content/js/jquery.heroCarousel.css")"/>
    <link rel="stylesheet" media="screen" type="text/css" href="@Url.Content("~/Content/css/fonts.css")"/>
    <link rel="stylesheet" media="screen" type="text/css" href="@Url.Content("~/Content/css/hammer_styles.css")"/>
    <link rel="stylesheet" media="screen" type="text/css" href="@Url.Content("~/Content/css/target.css")"/>
@*    <link rel="stylesheet" media="screen" type="text/css" href="@Url.Content("~/Content/css/seller_profile.css")" />*@
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    @*
                                                                                                                                                                                                                                                                                
    *@
    <script type="text/javascript">
        function getURLParameter(name) {
            return decodeURI(
                (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
            );
        }
        var code = getURLParameter('code');
        if (code != 'null') {
            window.location = (window.location).toString().replace('code='+code,'');
        }
        window.fbAsyncInit = function () {
            // init the FB JS SDK
            FB.init({
                appId: '479862562081214', // App ID from the App Dashboard
                channelUrl: '//' + window.location.hostname + '/channel.html', // Channel File for x-domain communication
                status: true, // check the login status upon init?
                cookie: true, // set sessions cookies to allow your server to access the session?
                xfbml: true  // parse XFBML tags on this page?
            });
            fbApiInit = true;
            // Additional initialization code such as adding Event Listeners goes here

        };

        // Load the SDK's source Asynchronously
        // Note that the debug version is being actively developed and might 
        // contain some type checks that are overly strict. 
        // Please report such bugs using the bugs tool.
        (function (d, debug) {
            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
            if (d.getElementById(id)) { return; }
            js = d.createElement('script'); js.id = id; js.async = true;
            js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
            ref.parentNode.insertBefore(js, ref);
        }(document, /*debug*/ false));

        function fbEnsureInit(callback) {
            if (!window.fbApiInit) {
                setTimeout(function () { fbEnsureInit(callback); }, 50);
            } else {
                if (callback) {
                    callback();
                }
            }
        }
        fbEnsureInit(function () {
            FB.getLoginStatus(function (response) {
                if (response.status == "connected" && localStorage['autologin'] == 'true' && $('#loaded').length == 0) {
                    $('#fbID').val(response.authResponse.userID);
                    FB.api('/me', function (resp) {
                        $('#fbname').val(resp.name);
                        $('#fbemail').val(resp.email);
                        $.ajax({
                            type: "POST",
                            url: '@Url.Action("SignUpFB","Home")',
                            data: $('#form-loginFB').serialize(), // serializes the form's elements.
                            success: function (d) {
                                window.location = window.location;
                            },
                        });
                    });
                    //}
                }
            });
        });
    </script>
    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.datepicker-vi.js")" type="text/javascript"></script>
    <style>
		.scrollCate{
			position:fixed;
			top: 120px;
			}
    </style>
    <script type="text/javascript" src="@Url.Content("~/Content/js/jquery.easing-1.3.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/js/jquery.heroCarousel-1.3.min.js")"></script>
    @if (IsSectionDefined("AddToHead"))
        {
            @RenderSection("AddToHead", required: false)
        }
</head>

<body>
    <div id="fb-root">
    </div>
    <div class="zbar zbar-fixed" id="zbar-v2">
    	<div class="zbar-item-home">
        	<a href="#"><span class="zbar-logo"></span></a>
        </div>
        <a id="show-cate" class="zbar-item-categories zbar-item zbar-item-button js-zbar-item-categories ss-list">Danh mục dịch vụ</a>
        <div id="list-cate" class="anim-load js-zbar-pane-categories container no-radius no-padding zbar-pane zbar-pane-categories" style="display: none;">
            <div class="clearfix">
                @foreach (var item in catgories)
                {
                    <a class="zbar-skill-category-item" href="@Url.Action("Search", "Provide", new { cid= item.ID})">@item.Name</a>
                }
            </div>
        </div>
        <a class="zbar-item-citypicker zbar-item zbar-item-button js-zbar-item-citypicker ss-location">Los Angeles</a>
        
        @if (User.Identity.IsAuthenticated && user !=null)
        {
            string avatar = user.Avatar ?? Url.Content("~/Content/img/blank-avatar.jpg");
            <div class="zbar-right" id="loaded">
                <a href="/inbox">
                <div class="zbar-item-inbox"></div>
                </a>
                <div class="zbar-item-user-profile">
                    <div class="stroke">
                        <img class="avatar avatar-small" src="@avatar">
                    </div>
                    <span class="name">
                    @user.ProperName
                    </span>
                        <ul class="zbar-menu">
                            <li>
                                <a href="@Url.Action("Profile","Profile")">My Profile</a></li>
                            <li><a href="@Url.Action("Account","Profile")">Account Settings</a></li>
                            <li><a href="javascript:;">The Help Center</a></li>
                            <li><a href="javascript:;" id="logout">Log Out</a></li>
                        </ul>
                    </div>
                <div class="zbar-sell-menu zbar-item">
                    <a class="btn" href="@Url.Action("sellingstart","home")">Sell On Zaarly</a>
                </div>
            </div>
        }
        else
        {
            <div class="zbar-right">
                <a class="zbar-item-plain" href="javascript:;">Hỏi đáp</a>
                <a class="zbar-item-edged login" id="login" href="javascript:;" rel="internal">Đăng nhập</a>
                <a class="btn zbar-join" href="javascript:;" rel="internal">Tham gia ngay</a>
            </div>
        }
    </div>
    @RenderBody()
    <div id="site-footer" class="anim-load anim-500 active">
        <div class="layout centered two-column-wide">
            <div class="layout-main">
                <div class="site-footer-column-navigation clearfix">
                	<h4>Navigation</h4>
                    <ul class="footerlinks">
                        <li><a href="#">How It Works</a> </li>
                        <li><a href="#" rel="manual">Help</a></li>
                        <li><a href="#">Safety</a></li>
                        <li><a href="#">Guarantee</a></li>
                    </ul>
                </div>
                </div>
              	<!--<div class="layout-right">
                    <h4>Get the Mobile App</h4>
                    <p>Available on the iPhone and Android. Enter your mobile number and we'll text you a link!</p>
                        <form id="footer-sms-form">
                            <input class="sms-form" name="mobile_number" placeholder="Mobile number" type="tel">
                            <div class="sms-form-submit ss-check" type="submit" value=""></div>
                        </form>
						<script>
                          //<![CDATA[
                            new Zaarly.smsWidget({el:'#footer-sms-form'})
                          //]]>
                        </script>
                    </div>-->
            	</div>
            <div class="site-footer-copyright layout centered">
            ©
            2013
            Guuuuuu
            </div>
    </div>

    <div class="unify-session-view unify" style="display:none" id="logindialog">
        <div class="container js-signin-modal signin-signup-modal">
        <div class="container-header simple">
            <div class="close js-close right ss-delete" id="close"></div>
          </div>
          <div class="modal-logo"></div>
          <h4>Buy from amazing local people.</h4>
          <div class="session-heros">
          <div class="anim-500 anim-scaleIn avatar-hero first active" style="background-image:url(@Url.Content("~/Content/img/kate.jpg"))"></div>
          <div class="anim-750 anim-scaleIn avatar-hero second active" style="background-image:url(@Url.Content("~/Content/img/kate.jpg"))"></div>
          <div class="anim-500 anim-scaleIn avatar-hero third active" style="background-image:url(@Url.Content("~/Content/img/kate.jpg"))"></div>
          <div class="sketchy-arrow"></div>
        </div>
          <button class="btn-facebook" id="btn-fblogin">Đăng nhập với Facebook</button>
          <p class="or">
            <span>or</span>
          </p>
            @using (Html.BeginForm("Login", "Home", FormMethod.Post, new { Class = "js-signin-form signin-signup-form", id = "form-login" }))
            {
            <div class="form-errors js-login-notification notification warning" style="display:none;" id="error"></div>
            <div class="field field-fixed">
              <label>Email</label>
              <div class="input">
                <input class="text-input" type="text" name="inputEmail" placeholder="you@example.com" id="email">
              </div>
            </div>
            <div class="field field-fixed">
              <label>Password</label>
              <div class="input">
                <input class="text-input" type="password" placeholder="Password" name="inputPassword" id="password">
              </div>
            </div>
            <div class="btn-small btn-submit left" id="btn-login">Login</div>
            <a class="forgot-password js-forgot-password" href="/session/forgot-password" rel="internal silent">Forgot Your Password?</a>
            }
          <div class="container-footer">
            <p class="signup-link">
              Don't have a login? <a href="@Url.Action("SignUp","User")" rel="internal silent">Sign Up.</a>
            </p>
          </div>
        </div>
        @*<p class="signup-terms">
          By signing up, you agree to our
          <a href="/tos" target="legal">Terms of Service</a>
          and have read our
            <a href="/privacy" target="legal">Privacy Policy</a>.
        </p>*@
    </div>
    @using (Html.BeginForm("LoginFB", "Home", FormMethod.Post, new { id="form-loginFB" }))
    {
        <input type="hidden" name="fbID" id="fbID" value=""/>
        <input type="hidden" name="fbname" id="fbname"value="" />
        <input type="hidden" name="fbemail" id="fbemail" value=""/>
    }
    <script type="text/javascript">
        $('#login').click(function () {
            $('#logindialog').dialog({
                modal: true,
                closeText: '',
                autoOpen: true,
                width: 462,
                height: 635,
                resizable: false,
                show: 'slow',
                hide: 'explode',
            });
        });
        $('#close').click(function () {
            $('#logindialog').dialog('close');
        });
        $('#btn-login').click(function () {
            if ($('#email').val().length > 0 && $('#password').val().length > 0) {
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("Login","Home")',
                    data: $("#form-login").serialize(), // serializes the form's elements.
                    success: function (data) {
                        console.log(data);
                        if (data) {
                            window.location = window.location;
                        } else {
                            $('#error').html('Email hoặc mật khẩu không đúng');
                            $('#error').show();
                        }
                    }
                });
            } else {
                $('#error').html('Nhập email và mật khẩu');
                $('#error').show();
            }
        });
        $('#show-cate').hover(function () {
            $('#list-cate').addClass('active');
           $('#list-cate').show();
        }, function () {
            $('#list-cate').removeClass('active');
           $('#list-cate').hide();
        });
        $('#list-cate').hover(function () {
            $('#list-cate').addClass('active');
            $('#list-cate').show();
        }, function () {
            $('#list-cate').removeClass('active');
            $('#list-cate').hide();
        });
        // login facebook
        
        
        $('#btn-fblogin').click(function () {
                FB.getLoginStatus(function (response) {
                    if (response.status == "connected") {
                        $('#fbID').val(response.authResponse.userID);
                        FB.api('/me', function (resp) {
                            $('#fbname').val(resp.name);
                            $('#fbemail').val(resp.email);
                            $.ajax({
                                type: "POST",
                                url: '@Url.Action("SignUpFB","Home")',
                                        data: $('#form-loginFB').serialize(), // serializes the form's elements.
                                        success: function (d) {
                                            localStorage['autologin'] = true;
                                            window.location = window.location;
                                        },
                                    });
                        });
                    } else {
                        var oauth_url = 'https://www.facebook.com/dialog/oauth/';
                        oauth_url += '?client_id=479862562081214';
                        oauth_url += '&redirect_uri=' + encodeURIComponent(window.location);
                        oauth_url += '&scope=email';
                        localStorage['autologin'] = true;
                        window.location = oauth_url;
                }
                });
        });
        $('#logout').click(function (e) {
            localStorage['autologin'] = false;
            window.location = '@Url.Action("LogOut", "Home")';
        });
    </script>
</body>
</html>
